package com.tianhua.javs.core.func.translate.javssdk;

import com.tianhua.javs.client.bean.JavsSegmentBean;
import com.tianhua.javs.core.annotations.Segment;
import com.tianhua.javs.client.func.ITranslatorFunc;
import org.springframework.stereotype.Component;

import java.util.stream.Collectors;

/**
 * Description:
 * date: 2022/2/12
 *
 * @author shenshuai
 * @version 1.0.0
 * @since JDK 1.8
 */
@Component(value = "cl")
@Segment(tag = "cl(",scriptFuncBean = "javaSDKFunc")
public class ClFunc implements ITranslatorFunc {
    @Override
    public JavsSegmentBean translate(String shellSegment) {
        Segment segment = ClFunc.class.getAnnotation(Segment.class);
        if(shellSegment.startsWith(segment.tag())){
            shellSegment = shellSegment.replaceFirst("cl\\(","collect(Collectors.toList())");
        }

        JavsSegmentBean javsSegmentBean = JavsSegmentBean.getMatchInstance(shellSegment);
        javsSegmentBean.addPackageName("java.util.stream.Collectors");
        return javsSegmentBean;
    }
}
